<template lang="html">
  <div>
    <div class="btn">
        <el-button type="primary" @click="back">返回上一级</el-button>
    </div>
    <div class="info">
      <div class="header">
          <img :src="data.avatar" alt="">
          <span class="zan" v-if="data.avatar == null">暂无头像</span>
      </div>
      <div class="infolist">
          <div v-for="(item,key) in data" :key="key" v-if="infoList[key]">
                <span class="item_table">{{infoList[key]}}</span>
                <span class="item_table item_content">{{item}}</span>
          </div>
      </div>
    </div>
    <div class="statisticsInfo">
        <h2>统计信息</h2>
        <div class="statisticstitle">
          <div class="box" v-for="(val,key) in statisticsdData" :key="key"  v-if="statisticsInfo[key]">
              <p class="title">
                {{statisticsInfo[key]}}
              </p>
              <p class="content">{{val}}</p>
          </div>
        </div>
    </div>
    <div class="sti">
    <el-collapse accordion @change="handleChange">
        <el-collapse-item title="购买记录"   name="1" >
            <div class="">
                <tableVue
                :total="recordtotal"
                 @sizeChange="recordhandSize"
                :list="purchaseList"
                :state="false">
                <slot>
                  <el-table-column label="商品名称" align="center">
                      <template slot-scope="scope">
                          <p v-for="(item,key) in scope.row.orderProducts">
                            <span>{{item.goodsName}}</span>
                          </p>
                      </template>
                  </el-table-column>
                  <el-table-column label="操作" align="center">
                      <template slot-scope="scope">
                          <el-button
                            size="mini"
                            @click="compile(scope.row)">详情
                          </el-button>
                      </template>
                    </el-table-column>
                </slot>
              </tableVue>
            </div>
        </el-collapse-item>
        <el-collapse-item title="寄卖记录" name="2">
          <div>
            <tableVue
            :total="consigntotal"
             @sizeChange="consignhandSize"
            :list="consignList"
            :state="false">
            <el-table-column label="操作" align="center">
                <template slot-scope="scope">
                    <el-button
                      size="mini"
                      @click="consignDetails(scope.row)">详情
                    </el-button>
                </template>
              </el-table-column>
          </tableVue>
          </div>
        </el-collapse-item>
        <el-collapse-item title="赎回记录" name="3">
          <div>
            <tableVue
            :total="redeemtotal"
             @sizeChange="redeemhandSize"
            :list="redeemList"
            :state="false">
            <el-table-column label="操作" align="center">
                <template slot-scope="scope">
                    <el-button
                      size="mini"
                      @click="redeemDetails(scope.row)">详情
                    </el-button>
                </template>
              </el-table-column>
          </tableVue>
          </div>
        </el-collapse-item>
        <el-collapse-item title="优惠券" name="4">
          <div>
            <tableVue
            :total="discounttotal"
             @sizeChange="discounthandSize"
            :list="discountList"
            :state="false">
          </tableVue>
          </div>
        </el-collapse-item>
        <el-collapse-item title="银行卡" name="5">
          <div>
            <tableVue
            :total="banktotal"
             @sizeChange="bankhandSize"
            :list="banktList"
            :state="false">
          </tableVue>
          </div>
        </el-collapse-item>
        <el-collapse-item title="提现记录" name="6">
          <div>
            <tableVue
            :total="withdrawtotal"
             @sizeChange="withdrawhandSize"
            :list="withdrawList"
            :state="false">
          </tableVue>
          </div>
        </el-collapse-item>
    </el-collapse>
    </div>
  </div>
</template>

<script>
import {
  userdetails,
  userRecord,
  userConsign,
  userRedeem,
  discountlist,
  bankList,
  withdrawlist
} from "@/api/userCenter/userlist";
import tableVue from '@/components/alltable.vue'
import Data from './index.js'
export default {
  components : {
    tableVue,
  },
    data () {
      return JSON.parse(JSON.stringify(Data))
    },
    mounted () {
      this.getuserdetails({size :'10'});
    },
    methods : {
      handleChange (val) {
        switch (val) {
          case '1' : this.getuserRecord({userId : this.$route.query.id,current : '1',size : '10'  });
          break;
          case '2' : this.getuserConsign({userId : this.$route.query.id,current : '1',size : '10'  });
          break;
          case '3' : this.getuserRedeem({userId : this.$route.query.id,current : '1',size : '10'  });
          break;
          case '4' : this.getdiscount({userId : this.$route.query.id,current : '1',size : '10'  });
          break;
          case '5' : this.getbank(this.$route.query.id);
          break;
          case '6' : this.getwithdrawList({userId : this.$route.query.id,current : '1',size : '10'});
          break;
          default:
        }
      },
      redeemhandSize (val) {//赎回分页
        var data = {
          current : val,
          size : '10'
        }
        this.getuserRedeem(data);
      },
      withdrawhandSize (val) {//提现分页

      },
      recordhandSize (val) {//购买记录分页
        var data = {
          current : val,
          size : '10'
        }
        this.getuserRecord(data);
      },
      discounthandSize (val) {//优惠券分页
        var data = {
          current : val,
          size : '10'
        }
        this.getdiscount(data);
      },
      bankhandSize (val) {//银行卡分页

      },
      consignhandSize (val) {//寄卖分页
        var data = {
          current : val,
          size : '10'
        }
        this.getuserConsign(data);
      },
      getbank (data) {//银行卡列表
          bankList (data).then(res=>{
            if ( res.data.code == 'OK') {
              this.banktList.tbody = res.data.data.bankList.map(item=>{
                 item.gmtCreate = this.switchTime(item.gmtCreate)
                 item.gmtUpdate = this.switchTime(item.gmtUpdate)
                 item.isEnable = item.isEnable == 'Y' ? '是' : '否'
                 return item;
              });
              this.banktotal = res.data.data.total;
            } else {
              this.$message.error(res.data.message)
            }
          })
      },
      getwithdrawList (data) {//提现列表
        withdrawlist(data).then(res=>{
          if (res.data.code == 'OK') {
            this.withdrawList.tbody = res.data.data.records.map(res=>{
                res.amount = res.amount /100;
                switch(res.funsStatus){
                     case "CREATEED":
                         res.funsStatus = "订单生成";
                         break;
                     case "FUNDING":
                         res.funsStatus = "代付中";
                         break;
                     case "SUCCESS":
                         res.funsStatus = "代付成功";
                         break;
                     case "FAILED":
                         res.funsStatus = "代付失败";
                         break;
                     case "COMPLETE":
                         res.funsStatus = "代付业务处理完成";
                         break;

                }
                return res

            });
            this.withdrawtotal = res.data.data.total;
          }else {
            this.$message.error(res.data.message)
          }
        })
      },
      getdiscount (data) {//优惠券列表
        discountlist(data).then(res=>{
          if (res.data.code == 'OK') {
            this.discounttotal = res.data.data.total;
            this.discountList.tbody = res.data.data.records.map(item=>{
                          item.gmtCreate = this.switchTime(item.gmtCreate)
                          item.gmtUpdate = this.switchTime(item.gmtUpdate);
                          item.receiveChannelDist=item.receiveChannelDist=="1"?"所有渠道都可以领取":"指定渠道可领取";
                          item.couponShape = item.couponShape == "10"?"现金":"折扣";
                          item.couponTpl = item.couponTpl =="1"?"默认模板":"";
                          item.isExpired = item.isExpired =="N"?"未使用":"已使用";
                          item.isUse = item.isUse =="N"?"未过期":"已过期";
                          item.receiveType = item.receiveType =="AUTO"?"系统下发":"用户主动领取";
                          item.useChannelDist=item.useChannelDist=="1"?"所有渠道都可以使用":"指定渠道可用";
                          item.logicalDeletion=item.logicalDeletion=="E"?"可用":'不可用';
                          switch(item.unProductType){
                                  case "PTC1001":
                                      item.unProductType = "所有寄卖商品";
                                      break;
                                  case "PTC1002":
                                          item.unProductType = "指定寄卖商品";
                                          break;
                                  case "PTC1003":
                                          item.unProductType = "指定某种品牌商品";
                                          break;
                                  case "PTC1004":
                                          item.unProductType = "指定某品牌商品";
                                          break;
                                  case "PTG1001":
                                          item.unProductType = "全部出售商品";
                                          break;
                                  case "PTG1002":
                                          item.unProductType = "指定出售商品";
                                          break;
                                  case "PTG1003":
                                          item.unProductType = "指定某种出售品牌类商品";
                                          break;
                                  case "PTG1004":
                                          item.unProductType = "指定某出售品牌商品";
                                          break;
                                  default:
                                      break;
                          }
                          switch(item.productType){
                                  case "PTC1001":
                                      item.unProductType = "所有寄卖商品";
                                      break;
                                  case "PTC1002":
                                          item.unProductType = "指定寄卖商品";
                                          break;
                                  case "PTC1003":
                                          item.unProductType = "指定某种品牌商品";
                                          break;
                                  case "PTC1004":
                                          item.unProductType = "指定某品牌商品";
                                          break;
                                  case "PTG1001":
                                          item.unProductType = "全部出售商品";
                                          break;
                                  case "PTG1002":
                                          item.unProductType = "指定出售商品";
                                          break;
                                  case "PTG1003":
                                          item.unProductType = "指定某种出售品牌类商品";
                                          break;
                                  case "PTG1004":
                                          item.unProductType = "指定某出售品牌商品";
                                          break;
                                  default:
                                      break;
                          }
                          switch(item.couponExpiredType){
                                  case "CET1010":
                                      item.couponExpiredType = "固定日期";
                                      break;
                                  case "CET1020":
                                          item.couponExpiredType = "领到券当日开始N天内有效";
                                          break;
                                  case "CET1030":
                                          item.couponExpiredType = "领到券次日开始N天内有效";
                                          break;
                                  default:
                                      break;
                          }
                          return item;
            });
          } else {
            this.$message.error(res.data.message)
          }
        })
      },
      getuserRedeem(data) {//赎回记录列表
        userRedeem(data).then(res=>{
            if (res.data.code == 'OK') {
              this.redeemtotal = res.data.data.total;
              this.redeemList.tbody = res.data.data.records.map(item=>{
                if (item.consignType == 'MEN_DIAN') {
                    item.consignType = '去门店'
                    switch (item.orderStatus) {
                      case 0 : item.orderStatus = '等待用户到店'
                        break;
                      case 1 : item.orderStatus = '用户到店'
                        break
                      case 4 : item.orderStatus = '订单完成（待打款）'
                        break
                      case 5 : item.orderStatus = '打款完成（可赎回）'
                        break
                      case 9 : item.orderStatus = '已取消'
                        break
                      case 10 : item.orderStatus = '待出库'
                        break
                      case 11 : item.orderStatus = '已出库'
                        break
                      case 12 : item.orderStatus = '待收货'
                        break
                      case 13 : item.orderStatus = '已赎回'
                        break
                      case 14 : item.orderStatus = '到期不可赎回'
                        break
                      default:
                    }
                } else if (item.consignType == 'SHANG_MEN') {
                    item.consignType = '上门'
                    switch (item.orderStatus) {
                      case 0 : item.orderStatus = '等待评估师上门'
                        break;
                      case 1 : item.orderStatus = '评估师已上门'
                        break
                      case 4 : item.orderStatus = '订单完成（待打款）'
                        break
                      case 5 : item.orderStatus = '打款完成（可赎回）'
                        break
                      case 9 : item.orderStatus = '已取消'
                        break
                      case 10 : item.orderStatus = '待出库'
                        break
                      case 11 : item.orderStatus = '已出库'
                        break
                      case 12 : item.orderStatus = '待收货'
                        break
                      case 13 : item.orderStatus = '已赎回'
                        break
                      case 14 : item.orderStatus = '到期不可赎回'
                        break
                      default:
                    }
                } else if (item.consignType == 'KUAIDI') {
                  item.consignType = '快递'
                  switch (item.orderStatus) {
                    case 0 : item.orderStatus = '待收货'
                      break;
                    case 1 : item.orderStatus = '已收货'
                      break
                    case 2 : item.orderStatus = '待估价'
                      break
                    case 3 : item.orderStatus = '已估价（用户可取消）'
                      break
                    case 4 : item.orderStatus = '订单完成（待打款）'
                      break
                    case 5 : item.orderStatus = '打款完成（可赎回）'
                      break
                    case 6 : item.orderStatus = '用户不同意'
                      break
                    case 7 : item.orderStatus = '待收货（用户不同意时）'
                      break
                    case 8 : item.orderStatus = '已完成（用户不同意时）'
                      break
                    case 10 : item.orderStatus = '待出库'
                      break
                    case 11 : item.orderStatus = '已出库'
                      break
                    case 12 : item.orderStatus = '待收货'
                      break
                    case 13 : item.orderStatus = '已赎回'
                      break
                    case 14 : item.orderStatus = '到期不可赎回'
                      break
                    default:
                  }
                } else {
                  item.consignType = '图片估计'
                  switch (item.orderStatus) {
                    case 0 : item.orderStatus = '待估价'
                      break;
                    case 1 : item.orderStatus = '已估价'
                      break
                    case 10 : item.orderStatus = '待出库'
                      break
                    case 11 : item.orderStatus = '已出库'
                      break
                    case 12 : item.orderStatus = '待收货'
                      break
                    case 13 : item.orderStatus = '已赎回'
                      break
                    case 14 : item.orderStatus = '到期不可赎回'
                      break
                    default:
                  }
                }
                 item.gmtCreate = this.switchTime(item.gmtCreate)
                 item.gmtUpdate = this.switchTime(item.gmtUpdate)
                 return item;
              });
            } else {
              this.$message.erro(res.data.message)
            }
        })
      },
      getuserConsign (data) {//寄卖记录列表
        userConsign(data).then(res=>{
          if (res.data.code == 'OK') {
            this.consignList.tbody = res.data.data.records.map(item=>{
              if (item.consignType == 'MEN_DIAN') {
                  item.consignType = '去门店'
                  switch (item.orderStatus) {
                    case 0 : item.orderStatus = '等待用户到店'
                      break;
                    case 1 : item.orderStatus = '用户到店'
                      break
                    case 4 : item.orderStatus = '订单完成（待打款）'
                      break
                    case 5 : item.orderStatus = '打款完成（可赎回）'
                      break
                    case 9 : item.orderStatus = '已取消'
                      break
                    case 10 : item.orderStatus = '待出库'
                      break
                    case 11 : item.orderStatus = '已出库'
                      break
                    case 12 : item.orderStatus = '待收货'
                      break
                    case 13 : item.orderStatus = '已赎回'
                      break
                    case 14 : item.orderStatus = '到期不可赎回'
                      break
                    default:
                  }
              } else if (item.consignType == 'SHANG_MEN') {
                  item.consignType = '上门'
                  switch (item.orderStatus) {
                    case 0 : item.orderStatus = '等待评估师上门'
                      break;
                    case 1 : item.orderStatus = '评估师已上门'
                      break
                    case 4 : item.orderStatus = '订单完成（待打款）'
                      break
                    case 5 : item.orderStatus = '打款完成（可赎回）'
                      break
                    case 9 : item.orderStatus = '已取消'
                      break
                    case 10 : item.orderStatus = '待出库'
                      break
                    case 11 : item.orderStatus = '已出库'
                      break
                    case 12 : item.orderStatus = '待收货'
                      break
                    case 13 : item.orderStatus = '已赎回'
                      break
                    case 14 : item.orderStatus = '到期不可赎回'
                      break
                    default:
                  }
              } else if (item.consignType == 'KUAIDI') {
                item.consignType = '快递'
                switch (item.orderStatus) {
                  case 0 : item.orderStatus = '待收货'
                    break;
                  case 1 : item.orderStatus = '已收货'
                    break
                  case 2 : item.orderStatus = '待估价'
                    break
                  case 3 : item.orderStatus = '已估价（用户可取消）'
                    break
                  case 4 : item.orderStatus = '订单完成（待打款）'
                    break
                  case 5 : item.orderStatus = '打款完成（可赎回）'
                    break
                  case 6 : item.orderStatus = '用户不同意'
                    break
                  case 7 : item.orderStatus = '待收货（用户不同意时）'
                    break
                  case 8 : item.orderStatus = '已完成（用户不同意时）'
                    break
                  case 9 : item.orderStatus = '已取消'
                    break
                  case 10 : item.orderStatus = '待出库'
                    break
                  case 11 : item.orderStatus = '已出库'
                    break
                  case 12 : item.orderStatus = '待收货'
                    break
                  case 13 : item.orderStatus = '已赎回'
                    break
                  case 14 : item.orderStatus = '到期不可赎回'
                    break
                  default:
                }
              } else {
                item.consignType = '图片估计'
                switch (item.orderStatus) {
                  case 0 : item.orderStatus = '待估价'
                    break;
                  case 1 : item.orderStatus = '已估价'
                    break
                  case 10 : item.orderStatus = '待出库'
                    break
                  case 11 : item.orderStatus = '已出库'
                    break
                  case 9 : item.orderStatus = '已取消'
                    break
                  case 12 : item.orderStatus = '待收货'
                    break
                  case 13 : item.orderStatus = '已赎回'
                    break
                  case 14 : item.orderStatus = '到期不可赎回'
                    break
                  default:
                }
              }
               item.gmtCreate = this.switchTime(item.gmtCreate)
               item.gmtUpdate = this.switchTime(item.gmtUpdate)
               return item;
            });
             this.consigntotal = res.data.data.total;
          } else {
            this.$message.error(res.data.message)
          }
        })
      },
      getuserRecord (data) {//用户购买记录
        userRecord(data).then(res=>{
           if (res.data.code == 'OK') {
             this.purchaseList.tbody = res.data.data.records.map(res=>{
                 switch (res.orderStatus) {
                     case "1000":
                         res.orderStatus="下单完成，未付款";
                         break;
                     case "1001":
                         res.orderStatus="已付款,待发货";
                         break;
                     case "1002":
                         res.orderStatus="已发货,待签收";
                         break;
                     case "1003":
                         res.orderStatus="已签收";
                         break;
                     case "1004":
                         res.orderStatus="退货申请";
                         break;
                     case "1005":
                         res.orderStatus="退货中";
                         break;
                     case "1006":
                         res.orderStatus="已退货";
                         break;
                     case "1007":
                         res.orderStatus="取消交易";
                         break;
                     default:
                         break;
                 }
                 return res;
             })
             this.recordtotal = res.data.data.total;
           } else {
             this.$message.error(res.data.message)
           }
        })
      },
      getuserdetails () {//基本信息
        userdetails (this.$route.query.id).then(res=>{
          if (res.data.code == 'OK') {
              this.data = res.data.data;
              this.statisticsdData = res.data.data;
              this.data.passTime = this.switchTime(this.data.passTime);
              this.data.isReal = this.data.isReal == 'Y' ? '已认证' : "未认证"
              this.data.isLock = this.data.isLock == 'Y' ? '已锁定' : "正常"
              if (this.data.sex  == 3) {
                  this.data.sex  = '保密'
              } else if (this.data.sex == 1) {
                this.data.sex = '男'
              } else {
                this.data.sex  = '女'
              }
          } else {
            this.$message.error(res.data.message);
          }
        })
      },
      back () {
        this.$router.push({
          name : 'userList'
        })
      },
      compile (val) {//购买记录详情
        this.$router.push({
          name : 'indentDetails',
          query : {
            data : JSON.stringify(val.orderId),
            num : '1',
            userId : this.$route.query.id
          }
        })
      },
      consignDetails (val) {//寄卖详情
        this.$router.push({
          name : 'details',
          query : {
            id : val.orderId,
            num : '3',
            userId : this.$route.query.id
          }
        })
      },
      redeemDetails (val) {//赎回详情
        this.$router.push({
          name : 'details',
          query : {
            id : val.orderId,
            num : '3',
            userId : this.$route.query.id
          }
        })
      }
    }
}
</script>

<style scoped>
  .btn {
    width: 100%;
    margin: 20px 0;
  }
  .info {
    display: flex;
    padding: 0 20px;
    box-sizing: border-box;
    padding-bottom: 20px;
    background: #fff;
    padding-top: 10px;
  }
  .header img {
    width: 200px;
    height: 200px;
  }
  .header {
    position: relative;
  }
  .zan {
    position: absolute;
    top: 30%;
    left: 35%;
  }
  .infolist {
    margin-left: 50px;
    display: flex;
    width: 800px;
    flex-wrap: wrap;

  }
  .infolist div {
    display: flex;
    border-bottom: 1px solid #ccc;
    height: 50px;
    /* flex-wrap: nowrap; */
  }
  .item_table {
    /* border: 1px solid #ccc; */
    border-top: 1px solid #ccc;
    border-left: 1px solid #ccc;
    border-right: 1px solid #ccc;
    width: 150px;
    height: 50px;
    display: inline-block;
    text-align: center;
    line-height: 50px;
  }
  .item_content {
    width: 200px;
    height: 50px;
    border-left: 0;
  }
  .statisticsInfo {
    height:230px;
    background: #fff;
  }
  .statisticsInfo h2 {
    text-indent: 10px;
    width: 100%;
    background: #99a9bf;
    height: 60px;
    line-height: 60px;
    color: #fff;
  }
  .statisticstitle {
    display: flex;
    justify-content: center;
    position: relative;
    /* height: 100%; */
  }
  .title {
    width:200px;
    height: 60px;
    line-height: 60px;
    text-align: center;
    border-top: 1px solid #ccc;
    border-right: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
    background: #99a9bf;

  }
  .content {
    width:200px;
    height: 60px;
    line-height: 60px;
    text-align: center;
    border-right: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
    position: absolute;
    top: 60px;
  }
  .sti {
    margin-top: 20px;
    padding-bottom: 50px;
    box-sizing: border-box;
  }
  .sti /deep/ .el-collapse-item__header {
    height: 60px;
    line-height: 60px;
    font-size: 20px;
    text-indent: 20px;
    font-weight: bold;
    background: #99a9bf;
    color: #fff;
  }
</style>
